import axios from "@/util/http";

export default {
  state: {
    review_list: [],
    food_rank_list: [],
    total_food_num: 0,
    server_rank_list: [],
    total_server_num: 0,
  },
  getters: {},
  mutations: {},
  actions: {
    add_review_to_food(context, data) {
      const url = "/review/add/review/by/food/id/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    add_review_to_server(context, data) {
      const url = "/review/add/review/by/server/id/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          data.success(resp.data);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    get_review_rank_about_food(context, data) {
      const url = "/review/get/review/rank/about/food/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          context.state.food_rank_list = resp.data.data;
          context.state.total_food_num = parseInt(resp.data.message);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
    get_review_rank_about_server(context, data) {
      const url = "/review/get/review/rank/about/server/";
      const config = {
        headers: {
          Authorization: "Bearer " + data.token,
        },
      };
      data.token = null;
      axios
        .post(url, data, config)
        .then((resp) => {
          context.state.server_rank_list = resp.data.data;
          context.state.total_server_num = parseInt(resp.data.message);
        })
        .catch((resp) => {
          console.log(resp);
        });
    },
  },
  modules: {},
};
